package com.ruoyi.third.service;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.third.base.InvoiceApiResult;

import com.ruoyi.third.entity.request.*;
import com.ruoyi.third.entity.result.*;
import com.ruoyi.third.entity.result.dto.BuyerBlurDto;
import com.ruoyi.third.entity.result.dto.InvoiceLingGouDto;
import com.ruoyi.third.entity.result.dto.TickConllinfQueryDto;
import com.ruoyi.utils.HttpUtils;
import com.ruoyi.utils.InvoiceApiPath;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ThirdApiService {

    @Resource
    private HttpUtils httpUtils;

    /**
     * 智能赋码
     *
     * @param name
     * @return
     */
    public InvoiceApiResult<JSONObject> intelligCoding(String name) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("name", name);
        return httpUtils.execute(InvoiceApiPath.INTELLIGCODING, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 商品编码查询（开具）
     *
     * @param nsrsbh
     * @return
     */
    public InvoiceApiResult commoditySearch(String nsrsbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("nsrsbh", nsrsbh);
        return httpUtils.execute(InvoiceApiPath.COMMODITYSEARCH, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 删除商品编码
     *
     * @param commodityDel
     * @return
     */
    public InvoiceApiResult commodityDel(CommodityDel commodityDel) {
        return httpUtils.execute(InvoiceApiPath.COMMODITYDEL, commodityDel, null, InvoiceApiResult.class);
    }

    /**
     * 添加商品编码
     *
     * @param commodityAdd
     * @return
     */
    public InvoiceApiResult addInvoiceSp(CommodityAdd commodityAdd) {
        return httpUtils.execute(InvoiceApiPath.ADDINVOICESP, commodityAdd, null, InvoiceApiResult.class);
    }

    /**
     * 开票单位查询
     *
     * @param billUnitSearch
     * @return
     */
    public InvoiceApiResult<List<BillUnit>> billUnitSearch(BillUnitSearch billUnitSearch) {
        return httpUtils.execute(InvoiceApiPath.BILL_UNIT_SEARCH, billUnitSearch, null, InvoiceApiResult.class);
    }

    /**
     * 添加开票单位
     *
     * @param billUnitAdd
     * @return
     */
    public InvoiceApiResult billUnitAdd(BillUnitAdd billUnitAdd) {
        JSONObject jsonObject = JSONUtil.parseObj(billUnitAdd);
        JSONObject requestJson = new JSONObject();
        requestJson.putOpt("data", jsonObject.toString());
        return httpUtils.execute(InvoiceApiPath.ADD_KPHXX, requestJson, null, InvoiceApiResult.class);
    }

    /**
     * 修改开票单位
     *
     * @param billUnitEdit
     * @return
     */
    public InvoiceApiResult billUnitEdit(BillUnitEdit billUnitEdit) {
        JSONObject jsonObject = JSONUtil.parseObj(billUnitEdit);
        JSONObject requestJson = new JSONObject();
        requestJson.putOpt("data", jsonObject.toString());
        return httpUtils.executeJson(InvoiceApiPath.EDIT_KPHXX, requestJson, null, InvoiceApiResult.class);
    }

    /**
     * 删除开票单位
     *
     * @param nsrsbh 纳税人识别号
     * @return
     */
    public InvoiceApiResult billUnitDel(String nsrsbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("nsrsbh", nsrsbh);
        return httpUtils.execute(InvoiceApiPath.DEL_KPHXX, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 购货单位此信息查询
     *
     * @param buyerSearch
     * @return
     */
    public InvoiceApiResult<List<Buyer>> buyerSearch(BuyerSearch buyerSearch) {
        return httpUtils.execute(InvoiceApiPath.BUYER_SEARCH, buyerSearch, null, InvoiceApiResult.class);
    }

    /**
     * 新增购货单位此信息
     *
     * @param buyerAdd
     * @return
     */
    public InvoiceApiResult buyerAdd(BuyerAdd buyerAdd) {
        return httpUtils.execute(InvoiceApiPath.ADD_BUYER, buyerAdd, null, InvoiceApiResult.class);
    }

    /**
     * 修改购货单位此信息
     *
     * @param buyerEdit
     * @return
     */
    public InvoiceApiResult buyerEdit(BuyerEdit buyerEdit) {
        return httpUtils.execute(InvoiceApiPath.EDIT_BUYER, buyerEdit, null, InvoiceApiResult.class);
    }

    /**
     * 删除购货单位此信息
     *
     * @param id
     * @return
     */
    public InvoiceApiResult buyerDel(String id) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("id", id);
        return httpUtils.execute(InvoiceApiPath.DEL_BUYER, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 模糊查询购货单位此信息
     *
     * @param buyerSearchBlur
     * @return
     */
    public InvoiceApiResult<BuyerBlurDto> buyerSearchBlur(BuyerSearchBlur buyerSearchBlur) {
        return httpUtils.execute(InvoiceApiPath.FUZZY_QUERY_BUYER, buyerSearchBlur, null, InvoiceApiResult.class);
    }

    /**
     * 获取税种税目信息
     *
     * @param jqbh
     * @return
     */
    public InvoiceApiResult<List<Szsm>> szsm(String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.OBTAIN_SZSM_ATION, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 税控盘信息查询
     *
     * @param jqbh
     * @return
     */
    public InvoiceApiResult<Skp> SkpInfo(String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.SKP_INFORMATION, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 监控管理信息查询
     *
     * @param jqbh
     * @return
     */
    public InvoiceApiResult<MonitorStrationData> monitorStrationData(String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.MONITOR_STRATION_DATA, jsonObject, null, InvoiceApiResult.class);
    }


    /**
     * 发票领购信息查询
     *
     * @param jqbh
     * @param fplxdm
     * @return
     */
    public InvoiceApiResult<List<InvoiceLingGouDto>> invoiceLinggou(String jqbh, String fplxdm) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("fplxdm", fplxdm);
        return httpUtils.execute(InvoiceApiPath.INVOICE_LINGGOU, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 19.同步登记信息
     *
     * @param jqbh
     * @return
     */
    public InvoiceApiResult synchronRegistInfor(String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.SYNCHRON_REGIST_INFOR, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 20.抄报状态查询
     *
     * @param queryCopyNewParam
     * @return
     */
    public InvoiceApiResult<List<QueryCopyNew>> queryCopyNew(QueryCopyNewParam queryCopyNewParam) {
        return httpUtils.execute(InvoiceApiPath.QUERY_COPY_NEW, queryCopyNewParam, null, InvoiceApiResult.class);
    }

    /**
     * 21.发票同步
     *
     * @param invoiceSync
     * @return
     */
    public InvoiceApiResult synchronization(InvoiceSync invoiceSync) {
        return httpUtils.executeJson(InvoiceApiPath.SYNCHRONIZATION, invoiceSync, null, InvoiceApiResult.class);
    }

    /**
     * 22.发票修复
     *
     * @param invoiceSync
     * @return
     */
    public InvoiceApiResult<JSONArray> invoiceRepair(InvoiceSync invoiceSync) {
        return httpUtils.executeJson(InvoiceApiPath.INVOICE_REPAIR, invoiceSync, null, InvoiceApiResult.class);
    }

    /**
     * 23.网上领购查询
     *
     * @param jqbh
     * @return
     */
    public InvoiceApiResult<TickConllinfQueryDto> tickConllinfQuery(String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.TICK_CONLLINF_QUERY, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 24.网上领购录入
     *
     * @param onlineConllinf
     * @return
     */
    public InvoiceApiResult onlineConllinfQuery(OnlineConllinf onlineConllinf) {
        return httpUtils.execute(InvoiceApiPath.ONLINE_TICKET_COLL, onlineConllinf, null, InvoiceApiResult.class);
    }

    /**
     * 25.申领准备信息查询
     *
     * @param jqbh
     * @param nsrsbh
     * @return
     */
    public InvoiceApiResult<JSONObject> apppreparInforIn(String jqbh, String nsrsbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("nsrsbh", nsrsbh);
        return httpUtils.execute(InvoiceApiPath.APPPREPAR_INFOR_IN, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 26.发票申领
     *
     * @param invoiceApp
     * @return
     */
    public InvoiceApiResult invoiceApp(InvoiceApp invoiceApp) {
        return httpUtils.execute(InvoiceApiPath.INVOICE_APP, invoiceApp, null, InvoiceApiResult.class);
    }

    /**
     * 27 发票申领状态查
     *
     * @param invoiceApp
     * @return
     */
    public InvoiceApiResult<JSONObject> invocieAppStateSearch(InvoiceApp invoiceApp) {
        return httpUtils.execute(InvoiceApiPath.INVOCIE_APPSTATE_SEARCH, invoiceApp, null, InvoiceApiResult.class);
    }

    /**
     * * 28.网上纸票接受确认接口
     *
     * @param paperAcceptCon
     * @return
     */
    public InvoiceApiResult<JSONObject> invocieAppStateSearch(PaperAcceptCon paperAcceptCon) {
        return httpUtils.execute(InvoiceApiPath.PAPER_ACCEPT_CON, paperAcceptCon, null, InvoiceApiResult.class);
    }

    /**
     * 29.网上申领撤销接口
     *
     * @param cancellOfOnline
     * @return
     */
    public InvoiceApiResult<JSONObject> cancellOfOnline(CancellOfOnline cancellOfOnline) {
        return httpUtils.execute(InvoiceApiPath.CANCELL_OF_ONLINE, cancellOfOnline, null, InvoiceApiResult.class);
    }

    /**
     * 30.获取当前未开票号
     *
     * @param jqbh
     * @param fplxdm
     * @return
     */
    public InvoiceApiResult<JSONObject> obtainNoticNumber(String jqbh, String fplxdm) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("fplxdm", fplxdm);
        return httpUtils.execute(InvoiceApiPath.OBTAIN_NOTIC_NUMBER, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 31.专电普开票
     *
     * @param invoiveFillIn
     * @return
     */
    public InvoiceApiResult<JSONObject> fillInInvoice(InvoiceFillIn invoiveFillIn) {
        List<Fyxm> fyxms = invoiveFillIn.getFyxm();
        String[] fyxmProperties = {"fphxz", "spmc", "spsm", "ggxh", "dw", "spsl", "dj", "je", "sl", "se", "hsbz", "spbm", "zxbm", "yhzcbs", "lslbs", "zzstsgl"};
        JSONObject invoiveFillInJson = JSONUtil.parseObj(invoiveFillIn);
        invoiveFillInJson.remove("fyxm");
        for (int i = 0; i < fyxms.size(); i++) {
            Fyxm fyxm = fyxms.get(i);
            JSONObject fyxmJson = JSONUtil.parseObj(fyxm);
            for (int i1 = 0; i1 < fyxmProperties.length; i1++) {
                invoiveFillInJson.putOpt(StrUtil.format("fyxm[{}][{}]", i, fyxmProperties[i1]), fyxmJson.getStr(fyxmProperties[i1]));
            }
        }
        return httpUtils.execute(InvoiceApiPath.FILL_IN_INVOICE, invoiveFillInJson, null, InvoiceApiResult.class);
    }

    /**
     * 32.发票作废
     *
     * @param invoiceVoid
     * @return
     */
    public InvoiceApiResult<JSONObject> voidBlankInvoice(InvoiceVoid invoiceVoid) {
        return httpUtils.execute(InvoiceApiPath.VOID_BLANK_INVOICE, invoiceVoid, null, InvoiceApiResult.class);
    }

    /**
     * 33.红字信息表申请
     *
     * @param invoiveRed
     * @return
     */
    public InvoiceApiResult<JSONObject> scarletLetterSq(InvoicRed invoiveRed) {
        List<InvoicRed.Fyxm> fyxms = invoiveRed.getFyxm();
        String[] fyxmProperties = {"fphxz", "spmc", "spsm", "ggxh", "dw", "spsl", "dj", "je", "sl", "se", "hsbz", "spbm", "zxbm", "yhzcbs", "lslbs", "zzstsgl"};
        JSONObject invoiveRedJson = JSONUtil.parseObj(invoiveRed);
        invoiveRedJson.remove("fyxm");
        for (int i = 0; i < fyxms.size(); i++) {
            InvoicRed.Fyxm fyxm = fyxms.get(i);
            JSONObject fyxmJson = JSONUtil.parseObj(fyxm);
            for (int i1 = 0; i1 < fyxmProperties.length; i1++) {
                invoiveRedJson.putOpt(StrUtil.format("fyxm[{}][{}]", i, fyxmProperties[i1]), fyxmJson.getStr(fyxmProperties[i1]));
            }
        }
        return httpUtils.execute(InvoiceApiPath.SCARLET_LETTER_SQ, invoiveRedJson, null, InvoiceApiResult.class);
    }

    /**
     * 34.获取当前未开票号
     *
     * @param jqbh
     * @param sqlsh
     * @param xxbbh
     * @return
     */
    public InvoiceApiResult<JSONObject> scarletLetterRevoke(String jqbh, String sqlsh, String xxbbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("sqlsh", sqlsh);
        jsonObject.putOpt("xxbbh", xxbbh);
        return httpUtils.execute(InvoiceApiPath.SCARLET_LETTER_REVOKE, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 35.发票查询
     *
     * @param invoiceQueryParam
     * @return
     */
    public InvoiceApiResult<JSONObject> InvoiceQueryDb(InvoiceQueryDbParam invoiceQueryParam) {
        return httpUtils.execute(InvoiceApiPath.INVOICE_QUERY_DB, invoiceQueryParam, null, InvoiceApiResult.class);
    }

    /**
     * 36.发票详情查询
     *
     * @param invoiceQueryMaxParam
     * @return
     */
    public InvoiceApiResult<JSONObject> InvoiceQueryDb(InvoiceQueryMaxParam invoiceQueryMaxParam) {
        return httpUtils.execute(InvoiceApiPath.INVOICE_QUERY_MAX, invoiceQueryMaxParam, null, InvoiceApiResult.class);
    }

    /**
     * 37.生成PDF
     *
     * @param invoiceCreatePdfParam
     * @return
     */
    public InvoiceApiResult<JSONObject> InvoiceCreatePdf(InvoiceCreatePdfParam invoiceCreatePdfParam) {
        return httpUtils.execute(InvoiceApiPath.INVOICE_CREATE_PDF, invoiceCreatePdfParam, null, InvoiceApiResult.class);
    }

    /**
     * 38.下载PDF
     *
     * @param jqbh
     * @param fplxdm
     * @param ids
     * @return
     */
    public InputStream InvoicePdfDownload(String jqbh, String fplxdm, String ids) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("fplxdm", fplxdm);
        jsonObject.putOpt("ids", ids);
        return httpUtils.executeGetStream(InvoiceApiPath.INVOICE_PDF_DOWNLOAD, jsonObject, null);
    }

    /**
     * 39. 下载OFD
     *
     * @param jqbh
     * @param fpdm
     * @param fphm
     * @return
     */
    public InvoiceApiResult<String> InvoicePdfDownloadOfd(String jqbh, String fpdm, String fphm) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("fpdm", fpdm);
        jsonObject.putOpt("fphm", fphm);
        return httpUtils.execute(InvoiceApiPath.INVOICE_DOWNLOAD_OFD, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 40.电子专票下载板式文件 OFD/PDF(返回 url)
     *
     * @param jqbh
     * @param downflag 1:ofd 2:pdf 3:预
     * @param fpdm
     * @param fphm
     * @return
     */
    public InvoiceApiResult<String> dzPdfOrDown(String jqbh, String downflag, String fpdm, String fphm) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("downflag", downflag);
        jsonObject.putOpt("fpdm", fpdm);
        jsonObject.putOpt("fphm", fphm);
        return httpUtils.execute(InvoiceApiPath.DZPDF_OR_DOWN, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 41.红字信息表查询
     *
     * @param invoiceRedQueryParam
     * @return
     */
    public InvoiceApiResult<JSONObject> queryHzxxb(InvoiceRedQueryParam invoiceRedQueryParam) {
        return httpUtils.execute(InvoiceApiPath.QUERY_HZXXB, invoiceRedQueryParam, null, InvoiceApiResult.class);
    }

    /**
     * 42.抄报接口
     *
     * @param jqbh
     * @param fplxdm
     * @return
     */
    public InvoiceApiResult copyNew(String jqbh, String fplxdm) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("fplxdm", fplxdm);
        return httpUtils.execute(InvoiceApiPath.COPY_NEW, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 43.反写接口
     *
     * @param jqbh
     * @param fplxdm
     * @return
     */
    public InvoiceApiResult reverseWrite(String jqbh, String fplxdm) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("fplxdm", fplxdm);
        return httpUtils.execute(InvoiceApiPath.REVERSE_WRITE, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 44.获取服务器状态
     *
     * @param jqbh
     * @return
     */
    public InvoiceApiResult<JSONObject> obtainServerEssInfor(String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.OBTAIN_SERVER_ESS_INFOR, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 45.发票查询接口（查盘：用于发票修复）
     *
     * @param invoiceQueryParam
     * @return
     */
    public InvoiceApiResult<JSONObject> invoiceQuery(InvoiceQueryParam invoiceQueryParam) {
        return httpUtils.execute(InvoiceApiPath.INVOICE_QUERY, invoiceQueryParam, null, InvoiceApiResult.class);
    }

    /**
     * 46. 开票员注册
     *
     * @param createUser
     * @return
     */
    public InvoiceApiResult createUser(CreateUser createUser) {
        Map<String, String> extHeader = new HashMap<>(1);
        extHeader.put("Request-End", "web");
        return httpUtils.execute(InvoiceApiPath.CREATE_USER, createUser, extHeader, InvoiceApiResult.class);
    }

    /**
     * 47. 红字信息表上传
     *
     * @param jqbh
     * @param sqdh
     * @return
     */
    public InvoiceApiResult hzxxbSc(String jqbh, String sqdh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("sqdh", sqdh);
        return httpUtils.execute(InvoiceApiPath.HZXXB_SC, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 48. 红字信息表下载
     *
     * @param reviewDownload
     * @return
     */
    public InvoiceApiResult<JSONObject> reviewDownload(ReviewDownload reviewDownload) {
        return httpUtils.execute(InvoiceApiPath.REVIEW_DOWNLOAD, reviewDownload, null, InvoiceApiResult.class);
    }

    /**
     * 49.进项录入信息导出
     *
     * @param inputlistExportParam
     * @return
     */
    public InvoiceApiResult<JSONObject> inputlistExport(InputlistExportParam inputlistExportParam) {
        return httpUtils.execute(InvoiceApiPath.INPUTLIST_EXPORT, inputlistExportParam, null, InvoiceApiResult.class);
    }

    /**
     * 50. 票种核定接口
     *
     * @param fplxdm
     * @param nsrsbh
     * @param jqbh
     * @return
     */
    public InvoiceApiResult<JSONObject> queryinvoiceTypeCode(String fplxdm, String nsrsbh, String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("fplxdm", fplxdm);
        jsonObject.putOpt("nsrsbh", nsrsbh);
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.QUERYINVOICE_TYPE_CODE, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 51.智能赋码
     *
     * @param name 商品名称
     * @return
     */
    public InvoiceApiResult<JSONObject> seachIntelligenceCoding(String name) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("name", name);
        return httpUtils.execute(InvoiceApiPath.SEACH_INTELLIGENCE_CODING, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 52. 查询开票单位信息 id 接口
     *
     * @param jqbh 机器编号
     * @return
     */
    public InvoiceApiResult<JSONObject> searchKphxxById(String jqbh) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("jqbh", jqbh);
        return httpUtils.execute(InvoiceApiPath.SEARCH_KPHXX_BY_ID, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 53. 发票统计查询接口
     *
     * @param reportQueryParam
     * @return
     */
    public InvoiceApiResult<JSONObject> reportQuery(ReportQueryParam reportQueryParam) {
        return httpUtils.execute(InvoiceApiPath.REPORT_QUERY, reportQueryParam, null, InvoiceApiResult.class);
    }

    /**
     * 54. 导入红字信息表
     *
     * @param fplxdm
     * @param jqbh
     * @param file
     * @return
     */
    public InvoiceApiResult inputHzxxbInvoice(String fplxdm, String jqbh, String file) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("fplxdm", fplxdm);
        jsonObject.putOpt("jqbh", jqbh);
        jsonObject.putOpt("file", file);
        return httpUtils.execute(InvoiceApiPath.INPUT_HZXXB_INVOICE, jsonObject, null, InvoiceApiResult.class);
    }


    //-------------------------------------- 全店开票-----------------------------------------

    /**
     * 获取短信验证
     * @param dppToken
     * @return
     */
    public InvoiceApiResult getDppToken(DppToken dppToken){
        return httpUtils.executeQd(InvoiceApiPath.getDpptToken, dppToken, null, InvoiceApiResult.class);
    }

    /**
     * 获取人俩你二维码
     * @param faceImg
     * @return
     */
    public InvoiceApiResult getFaceImg(FaceImg faceImg){
        return httpUtils.executeGetQd(InvoiceApiPath.getFaceImg, faceImg   , null, InvoiceApiResult.class);
    }

    /**
     * 获取是否需要人脸
     * @param nsrsbh 纳税人识别号
     * @return
     */
    public InvoiceApiResult queryFaceAuthState(String nsrsbh){
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("nsrsbh", nsrsbh);
        return httpUtils.executeQd(InvoiceApiPath.queryFaceAuthState, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 获取短信验证
     *
     * @param blueTicket
     * @return
     */
    public InvoiceApiResult blueTicket(BlueTicket blueTicket){
        List<BlueTicketFyxm> fyxms = blueTicket.getFyxm();
        JSONObject blueTicketJson = JSONUtil.parseObj(blueTicket);
        blueTicketJson.remove("fyxm");
        if(fyxms!=null && !fyxms.isEmpty()){
            List<String> fyxmProperties = BlueTicketFyxm.getProperties();
            for (int i = 0; i < fyxms.size(); i++) {
                BlueTicketFyxm fyxm = fyxms.get(i);
                JSONObject fyxmJson = JSONUtil.parseObj(fyxm);
                for (int i1 = 0; i1 < fyxmProperties.size(); i1++) {
                    blueTicketJson.putOpt(StrUtil.format("fyxm[{}][{}]", i, fyxmProperties.get(i1)), fyxmJson.getStr(fyxmProperties.get(i1)));
                }
            }
        }
        blueTicketJson.remove("hwys");
        List<BlueTicketHwys> hwyss = blueTicket.getHwys();
        if (hwyss != null && !hwyss.isEmpty()) {
            List<String> hwysProperties = BlueTicketFyxm.getProperties();
            for (int i = 0; i < hwyss.size(); i++) {
                BlueTicketHwys hwys = hwyss.get(i);
                JSONObject fyxmJson = JSONUtil.parseObj(hwys);
                for (int i1 = 0; i1 < hwysProperties.size(); i1++) {
                    blueTicketJson.putOpt(StrUtil.format("hwys[{}][{}]", i, hwysProperties.get(i1)), fyxmJson.getStr(hwysProperties.get(i1)));
                }
            }
        }
        return httpUtils.executeQd(InvoiceApiPath.blueTicket, blueTicketJson, null, InvoiceApiResult.class);
    }


    /**
     * 发票详细查询
     *
     * @param nsrsbh
     * @param fphm
     * @param fpqqlsh
     * @return
     */
    public InvoiceApiResult invoiceQueryMx(String nsrsbh,String fphm,String fpqqlsh){
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("nsrsbh", nsrsbh);
        jsonObject.putOpt("fphm", fphm);
        jsonObject.putOpt("fpqqlsh", fpqqlsh);
        return httpUtils.execute(InvoiceApiPath.invoiceQueryMx, jsonObject, null, InvoiceApiResult.class);
    }

    /**
     * 授信额度查询接口
     * @param nsrsbh 纳税人识别号
     * @return
     */
    public InvoiceApiResult getCreditLine(String nsrsbh){
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("nsrsbh", nsrsbh);
        return httpUtils.executeQd(InvoiceApiPath.getCreditLine, jsonObject, null, InvoiceApiResult.class);
    }


    /**
     * 获取版式文件
     * @param downflag
     * @param nsrsbh
     * @param fphm
     * @param kprq
     * @param addSeal
     * @return
     */
    public InvoiceApiResult getInvoicePdfOfd(String downflag,String nsrsbh,String fphm,String kprq,String addSeal){
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("downflag", downflag);
        jsonObject.putOpt("nsrsbh", nsrsbh);
        jsonObject.putOpt("fphm", fphm);
        jsonObject.putOpt("kprq", kprq);
        jsonObject.putOpt("addSeal", addSeal);
        return httpUtils.execute(InvoiceApiPath.getInvoicePdfOfd, jsonObject, null, InvoiceApiResult.class);
    }


    public InvoiceApiResult getFaceAuthResult(FaceImg faceImg) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("rzid", faceImg.getRzid());
        jsonObject.putOpt("nsrsbh", faceImg.getNsrsbh());
        return httpUtils.executeGetQd(InvoiceApiPath.getFaceState, jsonObject, null, InvoiceApiResult.class);
    }
}
